package LeetCode.leetcode230;

import java.util.ArrayList;

class Solution {
    int size = 0;
    int res = Integer.MAX_VALUE;
    public int kthSmallest(TreeNode root, int k) {
        dfs(root, k );
        return res;
    }
    public void dfs(TreeNode root, int k) {
        if (root == null || size >= k) return;
        dfs(root.left, k);
        if (++size == k) res  = root.val;
        dfs(root.right, k);
    }
}